BY Dhruv Parthasarathy
(Director of AI Programs @ Udacity)

how-eigenvectors-power-the-algorithm-behind-google-search-020ef637-9ba3-4cbb-96fc-e1ce80dcf129

P a g e R a n k P a g e R a n k PageRankPage\,RankPageRank


Welcome back! In the last post we derived Eigenvectors. In particular, we saw how useful they are in analyzing matrices we need to apply again and again.
In this post, we're going to dive into one of the most famous applications of Eigenvectors - the original PageRank algorithm that allowed Google to create the world's best search engine. PageRank was Larry Page's phD thesis while at Stanford. He spun out this amazing algorithm to redefine search and create one of the most iconic companies in the modern era. We're going to re-derive it here and see that it's just a simple application of Eigenvectors!
By the end of this post, you will:
  1. Feel like you could have come up with PageRank yourself.
  2. Understand how eigenvectors are central to PageRank.
  3. See how central eigenvectors are to dynamic processes in general.

Making Friends

Ok let's build out our understanding of pagerank using a hypothetical scenario.
Let's say you just moved to a new city and you’re trying to make some new friends. You need to figure out which of your new friends to hang out with in your free time. But unfortunately you’re super busy and have very little free time!
So you need to rank all these potential friends to prioritize which ones to chill with.

This could be you! Just need to find the friends...

In a moment of clarity you realize the following:
  1. Friends you’re close with are probably going to hang out with people you’d like.
  2. Someone everyone is friends with is probably someone you are going to be friends with.
You decide to use these two insights to create a scheme you call FriendRank.
FriendRank gives a potential friend a score (FriendScore) based on:
  1. How many people are friends with this person weighted by,
  2. How close you are to the people who are friends with them.
Embedded Image
In the above picture, how close you are to a person is shown by the size of the circle. To find your friend score for potential friend F F FFF, you just add up how close you are to A A AAA, C C CCC, and D D DDD.
Let’s write this down as a formula. Let’s say the strength of the friendship between you and some person p p ppp is F S ( p ) F S ( p ) FS(p)FS(p)FS(p). Let F r i e n d s ( p ) F r i e n d s ( p ) Friends(p)Friends(p)Friends(p) be the set of friends of p p ppp.
The FS (FriendScore) for a potential friend Fred is:
F S ( F r e d ) = p F r i e n d s ( F r e d ) F S ( p ) F S ( F r e d ) = p F r i e n d s ( F r e d ) F S ( p ) FS(Fred)=sum_(p in Friends(Fred))FS(p)FS(Fred) = \sum_{p \in Friends(Fred)} FS(p)FS(Fred)=pFriends(Fred)FS(p)

Calculating Our First Friend Score

Let’s work through an example. Say you have 4 potential friends:
  1. Jimmy (closeness score - 5)
  2. Maya (closeness score - 9)
  3. Lisa (closeness score - 8)
  4. Fred (?)
In this world, you’re really close to Maya (with a score of 9) and Lisa (8) but only kinda close to Jimmy (5).
Only Jimmy and Maya are friends with Fred.
Graphically, this is:
Embedded Image
Only Jimmy and Maya claim to be friends with Fred. Lisa seems to be tearing him apart.
So:
F S ( F r e d ) = F S ( J i m m y ) + F S ( M a y a ) F S ( F r e d ) = F S ( J i m m y ) + F S ( M a y a ) FS(Fred)=FS(Jimmy)+FS(Maya)FS(Fred) = FS(Jimmy) + FS(Maya)FS(Fred)=FS(Jimmy)+FS(Maya)
F S ( F r e d ) = 5 + 9 = 14 F S ( F r e d ) = 5 + 9 = 14 FS(Fred)=5+9=14FS(Fred) = 5 + 9 = 14FS(Fred)=5+9=14

Accounting For People who are Friends With Everyone

Not such a crazy idea right? You start this process and you realize one thing. Your really close friend Maya claims to be friends with EVERYONE. You start wondering, "Hmm maybe I need to downweight Maya’s opinion because she doesn’t really seem to be that picky”.
This is easy - we just divide Maya’s weighting score by how many people she claims to be friends with. That way if Maya claims 100 friends, his weighting for each friend is divided by 100. So our formula is now:
F S ( F r e d ) = p F r i e n d s ( F r e d ) F S ( p ) 1 N u m F r i e n d s ( p ) F S ( F r e d ) = p F r i e n d s ( F r e d ) F S ( p ) 1 N u m F r i e n d s ( p ) FS(Fred)=sum_(p in Friends(Fred))FS(p)*(1)/(NumFriends(p))FS(Fred) = \sum_{p \in Friends(Fred)} FS(p) \cdot \frac{1}{NumFriends(p)}FS(Fred)=pFriends(Fred)FS(p)1NumFriends(p)
Going back to our example, our score becomes:
F S ( F r e d ) = F S ( J i m m y ) 2 + F S ( M a y a ) 4 F S ( F r e d ) = F S ( J i m m y ) 2 + F S ( M a y a ) 4 FS(Fred)=(FS(Jimmy))/(2)+(FS(Maya))/(4)FS(Fred) = \frac{FS(Jimmy)}{2} + \frac{FS(Maya)}{4}FS(Fred)=FS(Jimmy)2+FS(Maya)4
F S ( F r e d ) = 5 2 + 9 4 = 4.75 F S ( F r e d ) = 5 2 + 9 4 = 4.75 FS(Fred)=(5)/(2)+(9)/(4)=4.75FS(Fred) = \frac{5}{2} + \frac{9}{4} = 4.75FS(Fred)=52+94=4.75
Awesome!
Let’s now simplify this formula a little.
  1. Let’s call the set of all friends F F FFF.
  2. Let I s F r i e n d s ( p , F r e d ) = { 1 if p calls Fred a friend 0 otherwise I s F r i e n d s ( p , F r e d ) = 1      if p calls Fred a friend 0      otherwise IsFriends(p,Fred)={[1,"if""p calls Fred a friend"],[0,"otherwise"]:}IsFriends(p, Fred) = \begin{cases} 1 & \text{if}\ \textrm{p calls Fred a friend} \\ 0 & \text{otherwise} \end{cases}IsFriends(p,Fred)={1if p calls Fred a friend0otherwise
    Then we can simplify our earlier formula as shown below:
F S ( F r e d ) = p F r i e n d s ( F r e d ) F S ( p ) 1 N u m F r i e n d s ( p ) F S ( F r e d ) = p F r i e n d s ( F r e d ) F S ( p ) 1 N u m F r i e n d s ( p ) FS(Fred)=sum_(p in Friends(Fred))FS(p)*(1)/(NumFriends(p))FS(Fred) = \sum_{p \in Friends(Fred)} FS(p) \cdot \frac{1}{NumFriends(p)}FS(Fred)=pFriends(Fred)FS(p)1NumFriends(p)
F S ( F r e d ) = p F F S ( p ) I s F r i e n d s ( p , F r e d ) N u m F r i e n d s ( p ) F S ( F r e d ) = p F F S ( p ) I s F r i e n d s ( p , F r e d ) N u m F r i e n d s ( p ) FS(Fred)=sum_(p in F)FS(p)*(IsFriends(p,Fred))/(NumFriends(p))FS(Fred) = \sum_{p \in F} FS(p) \cdot \frac{IsFriends(p, Fred)}{NumFriends(p)}FS(Fred)=pFFS(p)IsFriends(p,Fred)NumFriends(p)
All the people who aren’t friends with Fred just get $0$ terms which gives us the same thing.

So Who's Friends With Whom?

Ok this is looking great! You decide to go ahead and implement this scheme with your friends Bobby, Lauren, Daniel, Rony, and Saba. You start by asking all your friends to write down who they’re friends with! So you send them all the following email:
From: parry.lage@boogle.com
To: Bobby, Lauren, Daniel, Rony, Saba
Subject: Who are your friends?

My dearest "friends",

I’m trying to rank you and all my other potential friends and need your help to do so. Below is a list of people. Please put a 1 next to their name if you call them your friend.

Person Friends?
Bobby ___
Lauren ___
Daniel ___
Rony ___
Saba ___

Yours truly,
Parry Lage

P.S. Just because I'm sending you this email doesn't mean we're friends.
So Saba sends you something like this:
Person IsFriends
Bobby 1
Lauren 1
Daniel 0
Rony 0
Saba 0
Looking good so far! You then remember you need to downweight Saba’s score by how many friends she claims to have. She’s claiming 2 friends here so we divide by 2 giving us:
Person IsFriends
Bobby 1/2
Lauren 1/2
Daniel 0
Rony 0
Saba 0
Sweet.
You now decide to organize all your friends responses into a little table so that it’s easy to see. Each column of the table is a different friend. It looks like this (notice Saba's answers above are the last column in the table below):
Bobby Lauren Daniel Rony Saba
Bobby 0 1 1/3 0 1/2
Lauren 1/4 0 1/3 0 1/2
Daniel 1/4 0 0 0 0
Rony 1/4 0 0 0 0
Saba 1/4 0 1/4 1 0
This table is just a matrix, which we'll call A A AAA. The element i , j i , j i,ji,ji,j in the matrix is
A [ i , j ] = I s F r i e n d s ( j , i ) N u m F r i e n d s ( j ) A [ i , j ] = I s F r i e n d s ( j , i ) N u m F r i e n d s ( j ) A[i,j]=(IsFriends(j,i))/(NumFriends(j))A[i,j] = \frac{IsFriends(j, i)}{NumFriends(j)}A[i,j]=IsFriends(j,i)NumFriends(j)
For example, let's examine A [ 1 , 5 ] A [ 1 , 5 ] A[1,5]A[1,5]A[1,5]:
  • Person 1 1 111 is Bobby and Person 5 5 555 is Saba.
  • I s F r i e n d s ( 5 , 1 ) I s F r i e n d s ( 5 , 1 ) IsFriends(5,1)IsFriends(5,1)IsFriends(5,1) is whether Saba claims to be friends with Bobby. We saw in her response she did, so I s F r i e n d s ( 5 , 1 ) = 1 I s F r i e n d s ( 5 , 1 ) = 1 IsFriends(5,1)=1IsFriends(5,1) = 1IsFriends(5,1)=1.
  • N u m F r i e n d s ( 5 ) N u m F r i e n d s ( 5 ) NumFriends(5)NumFriends(5)NumFriends(5) is the number of friends Saba has (2). Hence N u m F r i e n d s ( 5 ) = 2 N u m F r i e n d s ( 5 ) = 2 NumFriends(5)=2NumFriends(5) = 2NumFriends(5)=2.
  • So A [ 1 , 5 ] = 1 2 A [ 1 , 5 ] = 1 2 A[1,5]=(1)/(2)A[1, 5] = \frac{1}{2}A[1,5]=12 just as it is in the table.
Notice additionally that I s F r i e n d s I s F r i e n d s IsFriendsIsFriendsIsFriends is not reflexive! For instance, Rony may claim to be friends with Saba, but in the above example, Saba doesn't call Ron a friend.
Hence, I s F r i e n d s ( R o n , S a b a ) = 1 I s F r i e n d s ( R o n , S a b a ) = 1 IsFriends(Ron,Saba)=1IsFriends(Ron, Saba) = 1IsFriends(Ron,Saba)=1, but I s F r i e n d s ( S a b a , R o n ) = 0 I s F r i e n d s ( S a b a , R o n ) = 0 IsFriends(Saba,Ron)=0IsFriends(Saba, Ron) = 0IsFriends(Saba,Ron)=0.

Adding Your Own Scores

You then decide you want to come up with an
initial guess for everyone's FriendScore!
There are some people you know better than others so this is really a guess for what your final FriendScore is for each of them. You write down the following and call it F S 0 F S 0 FS_(0)FS_{0}FS0 - your initial FriendScore:
Person FriendScore
Bobby 1
Lauren 1
Daniel 1
Rony 1
Saba 1

Combining Everyone's Opinion

Omg this is a lot more work than I expected.
Ok we now have the following:
  1. A A AAA - a Matrix who's elements are A [ i , j ] = I s F r i e n d s ( j , i ) N u m F r i e n d s ( j ) A [ i , j ] = I s F r i e n d s ( j , i ) N u m F r i e n d s ( j ) A[i,j]=(IsFriends(j,i))/(NumFriends(j))A[i,j] = \frac{IsFriends(j, i)}{NumFriends(j)}A[i,j]=IsFriends(j,i)NumFriends(j).
  2. F S 0 F S 0 FS_(0)FS_0FS0 - An initial guess of everyone's FriendScore.
Now that we know who's friends with who, we can figure out who's really likely to be our friend.
We'd like to come up with a new FriendScore F S 1 F S 1 FS_(1)FS_{1}FS1 based on this information.
How do we do that?
Recall from earlier our formula for Fred's FriendScore:
F S ( F r e d ) = p F F S ( p ) I s F r i e n d s ( p , F r e d ) N u m F r i e n d s ( p ) F S ( F r e d ) = p F F S ( p ) I s F r i e n d s ( p , F r e d ) N u m F r i e n d s ( p ) FS(Fred)=sum_(p in F)FS(p)*(IsFriends(p,Fred))/(NumFriends(p))FS(Fred) = \sum_{p \in F} FS(p) \cdot \frac{IsFriends(p, Fred)}{NumFriends(p)}FS(Fred)=pFFS(p)IsFriends(p,Fred)NumFriends(p)
So similarly, we want to update our rankings, F S 1 F S 1 FS_(1)FS_{1}FS1, for our friends to be:
Person FriendScore
Bobby p F F S ( p ) I s F r i e n d s ( p , B o b b y ) N u m F r i e n d s ( p ) p F F S ( p ) I s F r i e n d s ( p , B o b b y ) N u m F r i e n d s ( p ) sum_(p in F)FS(p)*(IsFriends(p,Bobby))/(NumFriends(p))\sum_{p \in F} FS(p) \cdot \frac{IsFriends(p, Bobby)}{NumFriends(p)}pFFS(p)IsFriends(p,Bobby)NumFriends(p)
Lauren p F F S ( p ) I s F r i e n d s ( p , L a u r e n ) N u m F r i e n d s ( p ) p F F S ( p ) I s F r i e n d s ( p , L a u r e n ) N u m F r i e n d s ( p ) sum_(p in F)FS(p)*(IsFriends(p,Lauren))/(NumFriends(p))\sum_{p \in F} FS(p) \cdot \frac{IsFriends(p, Lauren)}{NumFriends(p)}pFFS(p)IsFriends(p,Lauren)NumFriends(p)
Daniel p F F S ( p ) I s F r i e n d s ( p , D a n i e l ) N u m F r i e n d s ( p ) p F F S ( p ) I s F r i e n d s ( p , D a n i e l ) N u m F r i e n d s ( p ) sum_(p in F)FS(p)*(IsFriends(p,Daniel))/(NumFriends(p))\sum_{p \in F} FS(p) \cdot \frac{IsFriends(p, Daniel)}{NumFriends(p)}pFFS(p)IsFriends(p,Daniel)NumFriends(p)
Rony p F F S ( p ) I s F r i e n d s ( p , R o n y ) N u m F r i e n d s ( p ) p F F S ( p ) I s F r i e n d s ( p , R o n y ) N u m F r i e n d s ( p ) sum_(p in F)FS(p)*(IsFriends(p,Rony))/(NumFriends(p))\sum_{p \in F} FS(p) \cdot \frac{IsFriends(p, Rony)}{NumFriends(p)}pFFS(p)IsFriends(p,Rony)NumFriends(p)
Saba p F F S ( p ) I s F r i e n d s ( p , S a b a ) N u m F r i e n d s ( p ) p F F S ( p ) I s F r i e n d s ( p , S a b a ) N u m F r i e n d s ( p ) sum_(p in F)FS(p)*(IsFriends(p,Saba))/(NumFriends(p))\sum_{p \in F} FS(p) \cdot \frac{IsFriends(p, Saba)}{NumFriends(p)}pFFS(p)IsFriends(p,Saba)NumFriends(p)
Let's shorten our notation:
  1. Let I F I F IFIFIF be I s F r i e n d s I s F r i e n d s IsFriendsIsFriendsIsFriends
  2. Let N F N F NFNFNF be N u m F r i e n d s N u m F r i e n d s NumFriendsNumFriendsNumFriends
Then Bobby’s ideal new ranking is:
p F I F ( p , B o b b y ) N F ( p ) F S ( p ) p F I F ( p , B o b b y ) N F ( p ) F S ( p ) sum_(p in F)(IF(p,Bobby))/(NF(p))*FS(p)\sum_{p \in F} \frac{IF(p, Bobby)}{NF(p)} \cdot FS(p)pFIF(p,Bobby)NF(p)FS(p)
This looks an awful lot like this dot product (go ahead and compute it!):
[ I F ( B o b b y , B o b b y ) N F ( B o b b y ) I F ( L a u r e n , B o b b y ) N F ( L a u r e n ) I F ( D a n i e l , B o b b y ) N F ( D a n i e l ) I F ( R o n y , B o b b y ) N F ( R o n y ) I F ( S a b a , B o b b y ) N F ( S a b a ) ] [ F S ( B o b b y ) F S ( L a u r e n ) F S ( D a n i e l ) F S ( R o n y ) F S ( S a b a ) ] I F ( B o b b y , B o b b y ) N F ( B o b b y ) I F ( L a u r e n , B o b b y ) N F ( L a u r e n ) I F ( D a n i e l , B o b b y ) N F ( D a n i e l ) I F ( R o n y , B o b b y ) N F ( R o n y ) I F ( S a b a , B o b b y ) N F ( S a b a ) F S ( B o b b y ) F S ( L a u r e n ) F S ( D a n i e l ) F S ( R o n y ) F S ( S a b a ) [[(IF(Bobby,Bobby))/(NF(Bobby)),(IF(Lauren,Bobby))/(NF(Lauren)),(IF(Daniel,Bobby))/(NF(Daniel)),(IF(Rony,Bobby))/(NF(Rony)),(IF(Saba,Bobby))/(NF(Saba))]]*[[FS(Bobby)],[FS(Lauren)],[FS(Daniel)],[FS(Rony)],[FS(Saba)]]\begin{bmatrix} \frac{IF(Bobby, Bobby)}{NF(Bobby)} & \frac{IF(Lauren, Bobby)}{NF(Lauren)} & \frac{IF(Daniel, Bobby)}{NF(Daniel)} & \frac{IF(Rony, Bobby)}{NF(Rony)} & \frac{IF(Saba, Bobby)}{NF(Saba)} \end{bmatrix} \cdot \begin{bmatrix} FS(Bobby) \\ FS(Lauren) \\ FS(Daniel) \\ FS(Rony) \\ FS(Saba) \end{bmatrix}[IF(Bobby,Bobby)NF(Bobby)IF(Lauren,Bobby)NF(Lauren)IF(Daniel,Bobby)NF(Daniel)IF(Rony,Bobby)NF(Rony)IF(Saba,Bobby)NF(Saba)][FS(Bobby)FS(Lauren)FS(Daniel)FS(Rony)FS(Saba)]

Breaking Down the Dot Product - First Vector

Let's try and see if we have the two vectors in this dot product. Let's start with the first vector:
[ I F ( B o b b y , B o b b y ) N F ( B o b b y ) I F ( L a u r e n , B o b b y ) N F ( L a u r e n ) I F ( D a n i e l , B o b b y ) N F ( D a n i e l ) I F ( R o n y , B o b b y ) N F ( R o n y ) I F ( S a b a , B o b b y ) N F ( S a b a ) ] I F ( B o b b y , B o b b y ) N F ( B o b b y ) I F ( L a u r e n , B o b b y ) N F ( L a u r e n ) I F ( D a n i e l , B o b b y ) N F ( D a n i e l ) I F ( R o n y , B o b b y ) N F ( R o n y ) I F ( S a b a , B o b b y ) N F ( S a b a ) [[(IF(Bobby,Bobby))/(NF(Bobby)),(IF(Lauren,Bobby))/(NF(Lauren)),(IF(Daniel,Bobby))/(NF(Daniel)),(IF(Rony,Bobby))/(NF(Rony)),(IF(Saba,Bobby))/(NF(Saba))]]\begin{bmatrix} \frac{IF(Bobby, Bobby)}{NF(Bobby)} & \frac{IF(Lauren, Bobby)}{NF(Lauren)} & \frac{IF(Daniel, Bobby)}{NF(Daniel)} & \frac{IF(Rony, Bobby)}{NF(Rony)} & \frac{IF(Saba, Bobby)}{NF(Saba)} \end{bmatrix}[IF(Bobby,Bobby)NF(Bobby)IF(Lauren,Bobby)NF(Lauren)IF(Daniel,Bobby)NF(Daniel)IF(Rony,Bobby)NF(Rony)IF(Saba,Bobby)NF(Saba)]
Where can we find this vector?
Remember the elements of A A AAA are just A [ i , j ] = I F ( j , i ) N F ( j ) A [ i , j ] = I F ( j , i ) N F ( j ) A[i,j]=(IF(j,i))/(NF(j))A[i,j] = \frac{IF(j, i)}{NF(j)}A[i,j]=IF(j,i)NF(j). Let's look at A A AAA again, substituting the first row of the matrix with the formula representation - we'll see that it's the same as this vector!
Bobby Lauren Daniel Rony Saba
Bobby I F ( B o b b y , B o b b y ) N F ( B o b b y ) I F ( B o b b y , B o b b y ) N F ( B o b b y ) (IF(Bobby,Bobby))/(NF(Bobby))\frac{IF(Bobby, Bobby)}{NF(Bobby)}IF(Bobby,Bobby)NF(Bobby) I F ( L a u r e n , B o b b y ) N F ( L a u r e n ) I F ( L a u r e n , B o b b y ) N F ( L a u r e n ) (IF(Lauren,Bobby))/(NF(Lauren))\frac{IF(Lauren, Bobby)}{NF(Lauren)}IF(Lauren,Bobby)NF(Lauren) I F ( D a n i e l , B o b b y ) N F ( D a n i e l ) I F ( D a n i e l , B o b b y ) N F ( D a n i e l ) (IF(Daniel,Bobby))/(NF(Daniel))\frac{IF(Daniel, Bobby)}{NF(Daniel)}IF(Daniel,Bobby)NF(Daniel) I F ( R o n y , B o b b y ) N F ( R o n y ) I F ( R o n y , B o b b y ) N F ( R o n y ) (IF(Rony,Bobby))/(NF(Rony))\frac{IF(Rony, Bobby)}{NF(Rony)}IF(Rony,Bobby)NF(Rony) I F ( S a b a , B o b b y ) N F ( S a b a ) I F ( S a b a , B o b b y ) N F ( S a b a ) (IF(Saba,Bobby))/(NF(Saba))\frac{IF(Saba, Bobby)}{NF(Saba)}IF(Saba,Bobby)NF(Saba)
Lauren - - - -
Daniel - - - - -
Rony - - - - -
Saba - - - - -
Great so we have the first vector in the dot product.

Breaking Down the Dot Product - Second Vector

Let's now see if we can get the second one:
[ F S ( B o b b y ) F S ( L a u r e n ) F S ( D a n i e l ) F S ( R o n y ) F S ( S a b a ) ] F S ( B o b b y ) F S ( L a u r e n ) F S ( D a n i e l ) F S ( R o n y ) F S ( S a b a ) [[FS(Bobby)],[FS(Lauren)],[FS(Daniel)],[FS(Rony)],[FS(Saba)]]\begin{bmatrix} FS(Bobby) \\ FS(Lauren) \\ FS(Daniel) \\ FS(Rony) \\ FS(Saba) \end{bmatrix}[FS(Bobby)FS(Lauren)FS(Daniel)FS(Rony)FS(Saba)]
You've already created this vector when you came up with your initial guesses F S 0 F S 0 FS_(0)FS_{0}FS0 in the following table:
Person FriendScore
Bobby 1
Lauren 1
Daniel 1
Rony 1
Saba 1
So we have both vectors of the dot product needed for finding F S ( B o b b y ) F S ( B o b b y ) FS(Bobby)FS(Bobby)FS(Bobby).

  1. The first vector is just the first row of A A AAA.

  2. The second vector is F S 0 F S 0 FS_(0)FS_{0}FS0.


Matrix Multiplication To Find FriendScores

If we just multiply A F S 0 A F S 0 A*FS_(0)A \cdot FS_{0}AFS0 we compute this dot product and get F S ( B o b b y ) F S ( B o b b y ) FS(Bobby)FS(Bobby)FS(Bobby) in the first row of the resulting vector.
A F S 0 = [ p F F S ( p ) I s F r i e n d s ( p , B o b b y ) N u m F r i e n d s ( p ) ] = [ F S ( B o b b y ) ] A F S 0 = p F F S ( p ) I s F r i e n d s ( p , B o b b y ) N u m F r i e n d s ( p ) = F S ( B o b b y ) A*FS_(0)=[[sum_(p in F)FS(p)*(IsFriends(p,Bobby))/(NumFriends(p))],[-],[-],[-],[-]]=[[FS(Bobby)],[-],[-],[-],[-]]A \cdot FS_{0} = \begin{bmatrix} \sum_{p \in F} FS(p) \cdot \frac{IsFriends(p, Bobby)}{NumFriends(p)} \\ - \\ - \\ - \\ - \end{bmatrix} = \begin{bmatrix} FS(Bobby) \\ - \\ - \\ - \\ - \end{bmatrix}AFS0=[pFFS(p)IsFriends(p,Bobby)NumFriends(p)]=[FS(Bobby)]
More generally, you'll find that the second row of this vector is exactly F S ( L a u r e n ) F S ( L a u r e n ) FS(Lauren)FS(Lauren)FS(Lauren) etc, giving us:
A F S 0 = [ F S ( B o b b y ) F S ( L a u r e n ) F S ( D a n i e l ) F S ( R o n y ) F S ( S a b a ) ] A F S 0 = F S ( B o b b y ) F S ( L a u r e n ) F S ( D a n i e l ) F S ( R o n y ) F S ( S a b a ) A*FS_(0)=[[FS(Bobby)],[FS(Lauren)],[FS(Daniel)],[FS(Rony)],[FS(Saba)]]A \cdot FS_{0} = \begin{bmatrix} FS(Bobby) \\ FS(Lauren) \\ FS(Daniel) \\ FS(Rony) \\ FS(Saba) \end{bmatrix}AFS0=[FS(Bobby)FS(Lauren)FS(Daniel)FS(Rony)FS(Saba)]
So, if we call F S 1 F S 1 FS_(1)FS_{1}FS1 the result of folding in the results of A A AAA into your initial predictions, we get:
A F S 0 = F S 1 A F S 0 = F S 1 A*FS_(0)=FS_(1)A \cdot FS_{0} = FS_{1}AFS0=FS1

When Do We Stop?

Ok so we now have a super quick way of finding our next FriendScore. Just take our current guess, which we’ll call F S i F S i FS_(i)FS_iFSi, multiply it by A A AAA, and obtain F S i + 1 F S i + 1 FS_(i+1)FS_{i+1}FSi+1:
F S i + 1 = A F S i F S i + 1 = A F S i FS_(i+1)=A*FS_(i)FS_{i+1} = A \cdot FS_{i}FSi+1=AFSi
Everytime we compute A F S i A F S i A*FS_(i)A \cdot FS_{i}AFSi, we are updating our guess of our Friend Score with the rest of our friends opinions.
When do we stop this process? We stop when F S i + 1 F S i + 1 FS_(i+1)FS_{i+1}FSi+1 stops changing:
F S i + 1 = F S i = F S F S i + 1 = F S i = F S FS_(i+1)=FS_(i)=FS^(**)FS_{i+1} = FS_{i} = FS^*FSi+1=FSi=FS
At this point, which we call F S F S FS^(**)FS^*FS,
A F S = F S A F S = F S A*FS^(**)=FS^(**)A \cdot FS^* = FS^*AFS=FS
Does this look like the following?
A x = λ x A x = λ x Ax=lambda xAx = \lambda xAx=λx
Yes!
This is exactly the formula for an eigenvector!
So the final solution F S F S FS^(**)FS^*FS, is an eigenvector of A A AAA!

Seeing This Visually

How does F S i F S i FS_(i)FS_iFSi move to F S F S FS^(**)FS^*FS?
In many ways, the matrix A A AAA pulls F S i F S i FS_(i)FS_iFSi towards its eigenvector F S F S FS^(**)FS^*FS.
There’s an awesome visualization of this here by setosa.io that I highly recommend you check out. Here’s an extract directly from their writeup. In the below image, s 1 s 1 s1s1s1 is an eigenvector of A A AAA. Notice how as we keep applying A A AAA on v v vvv, we move closer to s 1 s 1 s1s1s1. In particular, the sequence v v vvv, A v A v AvAvAv, A 2 v A 2 v A^(2)vA^2vA2v, ... eventually ends up directly on s 1 s 1 s1s1s1.
Embedded Image
As you keep applying A A AAA on v v vvv, v v vvv gets pulled towards the eigenvector s 1 s 1 s_(1)s_1s1.
Similarly in FriendRank, as we keep multiplying F S 0 F S 0 FS_(0)FS_{0}FS0 by A A AAA, we get the sequence A F S 0 A F S 0 A*FS_(0)A \cdot FS_0AFS0, A 2 F S 0 A 2 F S 0 A^(2)*FS_(0)A^2 \cdot FS_0A2FS0, ... which eventually ends up on F S F S FS^(**)FS^*FS - the eigenvector of A A AAA.

From Friends to Pages

You’ve probably guessed at this point that you can switch the word friends to pages in the above and get PageRank! In the world of webpages:
  1. One webpage claims to be “friends” with another if it links out to the webpage.
  2. Google finds out who’s friends with who (our initial survey) by just crawling the web and finding out who links to who.
  3. The number of "friends" a webpage claims to have is just the number of links present on the webpage.
  4. We create the matrix A A AAA by crawling the web. Once we have it, we find its eigenvector to get an estimate of the PageRanks.
Embedded Image
To get PageRank, just replace people with pages.
Putting this together gives us a way of ranking all webpages on the internet for relevance!
I find it really cool how PageRank models the abstract concept of webpages using simple insights into how we interact as humans.
A few quick asides:
  1. The formula we've derived for PageRank is a simplified version of the actual one. To see the full formula, read the original paper here.
  2. Notice that PageRank is actually a next level pun. PageRank was written by Larry Page about ranking webpages - well done Larry.

Conclusion

So we’ve seen that eigenvectors are at the heart of one of the most important algorithms of all time! More generally, whenever you see a linear function being applied again and again and again (Like A A AAA), you are without a doubt going to be looking for the eigenvectors of that linear function/matrix. The eigenvectors will tell you where that process ends!
I hope you enjoyed this unique and powerful application of eigenvectors. In the next post kernels, we're going to step back into Matrix Algebra. We'll learn about Kernels (or Nullspaces) and visually see how they help us immediately grasp what matrices do to their inputs.